package com.zxl.designpattern.structure.composite;

import java.util.ArrayList;
import java.util.List;


/**
 * @author zxl
 * @version 1.0
 * @description 组合模式-具体组件(部门，树枝节点)
 * @date 2025/6/1 14:22
 */
public class Department implements OrganizationComponent {
    private String name;
    private List<OrganizationComponent> members = new ArrayList<>();

    public Department(String name) {
        this.name = name;
    }

    public void addMember(OrganizationComponent component) {
        members.add(component);
    }

    public void removeMember(OrganizationComponent component) {
        members.remove(component);
    }

    @Override
    public void displayInfo() {
        System.out.printf("部门: %s, 员工数量: %d%n", name, getEmployeeCount());
        for (OrganizationComponent member : members) {
            System.out.print("  ");
            member.displayInfo();
        }
    }

    @Override
    public int getEmployeeCount() {
        int count = 0;
        for (OrganizationComponent member : members) {
            count += member.getEmployeeCount();
        }
        return count;
    }
}